home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 08 - 1992 / 08.05 Sep 92 / IconEdit / UIconEdit.h < prev   
Encoding:
Text File  |  1989-12-09  |  6.7 KB  |  191 lines  |  [TEXT/MPS ]

  1. //------------------------------------------------------------------------------
  2. //    UIconEdit.h - Class declarations for UIconEdit.cp
  3. //
  4. //    Written by K.L. Colclasure for MacTutor, Dec 3, 1989
  5. //    Copyright © 1989 MacTutor, all rights reserved.
  6. //------------------------------------------------------------------------------
  7.  
  8. // This typedef makes it easier to declare Fields methods in
  9. // MPW C++:
  10. typedef pascal void (*FieldProcPtr) (StringPtr fieldName,
  11.     Ptr fieldAddr, short fieldType, void *link);
  12.  
  13. const OSType        kFileType    = 'IDOC';
  14. const OSType        kSignature    = 'ICED';
  15. const short            kBorder = 8;
  16. const short            kDefaultMagnification = 7;
  17.  
  18. //------------------------------------------------------------------------------
  19. class TIconBitMap : public TObject {
  20. //------------------------------------------------------------------------------
  21. public:
  22.     Handle            fDataHandle;    // Handle to the icon’s
  23.                                 // bitmap.
  24.     
  25.     // Initialize the IconBitMap object and allocate space for
  26.     // its data. 
  27.     virtual pascal void IIconBitMap (void);
  28.     // Free the icon’s bit map.
  29.     virtual pascal void Free (void);
  30.     // Set the contents of the icon bit map to the new bit map.
  31.     virtual pascal void SetIconBitMap (Handle theBitMap);
  32.     // Clear the icon map by setting its bits to zero.
  33.     virtual pascal void Clear (void);
  34.     // Invert the icon’s bit map.
  35.     virtual pascal void Invert (void);
  36.     // Return the state of the given bit.
  37.     virtual pascal Boolean GetBit (Point iconBit);
  38.     // Set the state of the given bit as indicated.
  39.     virtual pascal void SetBit (Point iconBit,
  40.         Boolean turnBitOn);
  41.     // Create a new icon object which is a copy of itself.
  42.     virtual pascal TIconBitMap *Copy (void);
  43.     // Copy icon data to an existing icon object.
  44.     virtual pascal void CopyDataTo (TIconBitMap *anIcon);
  45.     // Draw the icon’s bit map.
  46.     virtual pascal void Draw (Rect *area);
  47. #if qInspector
  48.     virtual pascal void Fields (FieldProcPtr DTF, void *link);
  49. #endif
  50. };
  51.  
  52. //------------------------------------------------------------------------------
  53. class TIconDocument : public TDocument {
  54. //------------------------------------------------------------------------------
  55. public:
  56.     TIconBitMap        *fIconBitMap; // The document’s icon
  57.                                      // object.
  58.     
  59.     // Initialize the document.
  60.     virtual pascal void IIconDocument (void);
  61.     // Sets the document’s data to represent a “new” 
  62.     // document.
  63.     virtual pascal void DoInitialState (void);
  64.     // Free allocated memory when the document is closed.
  65.     virtual pascal void Free (void);
  66.     // Create the window & view objects when a document’s
  67.     // opened.
  68.     virtual pascal void DoMakeViews (Boolean forPrinting);
  69.     // Set the state of the menu items to which this class
  70.     // responds.
  71.     virtual pascal void DoSetupMenus (void);
  72.     // Handle menu items specific to this class.
  73.     virtual pascal TCommand *DoMenuCommand (
  74.         CmdNumber whichCmd);
  75.     // Invert the bits of this document’s icon and redraw its
  76.     // views.
  77.     virtual pascal void InvertIcon (void);
  78. #if qInspector
  79.     virtual pascal void Fields (FieldProcPtr DTF, void *link);
  80. #endif
  81. };
  82.  
  83. //------------------------------------------------------------------------------
  84. class TIconView : public TView {
  85. //------------------------------------------------------------------------------
  86. public:
  87.     TIconDocument    *fIconDocument; // View’s icon
  88.                                       // document.
  89.     short            fMagnification; // Times to magnify
  90.                                  // icon.
  91.     
  92.     // Initialize the view from a resource template.
  93.     virtual pascal void IRes (TDocument *itsDocument,
  94.         TView *itsSuperView, Ptr *itsParams);
  95.     // Return the view’s minimum size.
  96.     virtual pascal void CalcMinSize (VPoint *minSize);
  97.     // Draw this view.
  98.     virtual pascal void Draw (Rect *area);
  99.     // Set the state of the menu items to which this class
  100.     // responds.
  101.     virtual pascal void DoSetupMenus (void);
  102.     // Handle menu items specific to this class.
  103.     virtual pascal TCommand *DoMenuCommand (
  104.         CmdNumber whichCmd);
  105.     // Set the view’s magnification.
  106.     virtual pascal void SetMagnification (
  107.         short newMagnification);
  108.     // Handle mouse clicks in this view.
  109.     virtual pascal TCommand *DoMouseCommand (
  110.         Point *theMouse, EventInfo *info,
  111.         Point *hysteresis);
  112.     // Convert the given mouse point to an icon bit.
  113.     virtual pascal Boolean PointToBit (Point thePoint,
  114.         Point *iconBit);
  115.     // Draw the given bit in the given state.
  116.     virtual pascal void DrawBit (Point theBit,
  117.         Boolean turnItOn);
  118. #if qInspector
  119.     virtual pascal void Fields (FieldProcPtr DTF, void *link);
  120. #endif
  121. };
  122.  
  123. //------------------------------------------------------------------------------
  124. class TDrawCommand : public TCommand {
  125. //------------------------------------------------------------------------------
  126. public:
  127.     TIconDocument    *fIconDocument; // Document
  128.                                       // affected.
  129.     TIconView        *fIconView;    // View affected.
  130.     TIconBitMap        *fIconBitMap;  // Icon affected.
  131.     Boolean            fTurnBitsOn;    // Turn bits on or off.
  132.     
  133.     // Initialize the command and associate it with a view.
  134.     virtual pascal void IDrawCommand (
  135.         TIconView *itsIconView);
  136.     // Constrain the mouse to be within the icon in the edit
  137.     // view.
  138.     virtual pascal void TrackConstrain (VPoint *anchorPoint,
  139.         VPoint *prevPoint, VPoint *nextPoint);
  140.     // Overridden to avoid standard feedback.
  141.     virtual pascal void TrackFeedback (VPoint *anchorPoint,
  142.         VPoint *nextPoint, Boolean turnItOn,
  143.         Boolean mouseMoved);
  144.     // Track the mouse.
  145.     virtual pascal TCommand *TrackMouse (
  146.         TrackPhase aTrackPhase, VPoint *anchorPoint,
  147.         VPoint *prevPoint, VPoint *nextPoint,
  148.         Boolean mouseMoved);
  149. #if qInspector
  150.     virtual pascal void Fields (FieldProcPtr DTF, void *link);
  151. #endif
  152. };
  153.  
  154. //------------------------------------------------------------------------------
  155. class TInvertCommand : public TCommand {
  156. //------------------------------------------------------------------------------
  157. public:
  158.     TIconDocument    *fIconDocument; // Document
  159.                                       // affected.
  160.     
  161.     // Initialize the command and associate it with a
  162.     // document.
  163.     virtual pascal void IInvertCommand (
  164.         TIconDocument *itsIconDocument);
  165.     // Implement the command by calling the document’s
  166.     // Invert method.
  167.     virtual pascal void DoIt (void);
  168.     // Implement undo by calling the document’s Invert
  169.     // method again.
  170.     virtual pascal void UndoIt (void);
  171.     // Implement redo by calling the document’s Invert
  172.     // method yet again.
  173.     virtual pascal void RedoIt (void);
  174. #if qInspector
  175.     virtual pascal void Fields (FieldProcPtr DTF, void *link);
  176. #endif
  177. };
  178.  
  179. //------------------------------------------------------------------------------
  180. class TIconApplication : public TApplication {
  181. //------------------------------------------------------------------------------
  182. public:
  183.     // Initialize the application and globals.
  184.     virtual pascal void IIconApplication (
  185.         OSType iconFileType);
  186.     // Create a document of type TIconDocument and return a 
  187.     // reference to it.
  188.     virtual pascal TDocument *DoMakeDocument (
  189.         CmdNumber itsCmdNumber);
  190. };
  191.